export default {
	data() {
		return {
			emptyType: 'order',
			emptyShow: false,
			pagenum: 1,
			pagesize: 10,
			downOption: {
				auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
			},
			upOption: {
				auto: false, // 不自动加载
				// page: {
				// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
				// 	size: 10 // 每页数据的数量
				// },
				noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				empty: {
					tip: '~ 暂无订单 ~', // 提示
					btnText: '去逛逛'
				}
			},
			categoryId: '',
			orderList: [], //列表数据
			canIUseGetUserProfile: false,
			ewmimage: '',
		};
	},
	props: {
		i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
		index: {
			// 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			type: Number,
			default () {
				return 0;
			}
		},
		listTop: {
			type: Number,
			default () {
				return 10;
			}
		},
		skeyword: {
			type: String,
			default () {
				return '';
			}
		},
		tabObj: {
			type: Object,
			default () {
				return;
			}
		}
	},
	watch: {
		skeyword(newVal, oldVal) {
			if (newVal) {
				// this.mescroll.resetUpScroll()
			}
		}
	},
	created() {
		//加判断 编辑页来的，请求列表接口
		// #ifdef MP-WEIXIN
		if (wx.getUserProfile) this.canIUseGetUserProfile = true;
		// #endif
	},
	methods: {
		/*下拉刷新的回调 */
		downCallback() {
			// this.pagenum = 1;
			// this.pagesize = 1;
			this.mescroll.resetUpScroll();
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback(page) {
			this.pagenum = page.num;
			this.pagesize = page.size;
			this.getOrderListData();
		},
		//点击空布局按钮的回调
		emptyClick() {
			this.$util.redirectTo('/pages/index/index/index', {}, 'redirectTo');
		},
		getJourneyStatus(rows, prop) {
			let str = "";
			switch (rows.journey_status) {
				case "20":
					str = "已发车";
					break;
				case "30":
					str = "已送达";
					break;
			}
			return str;
		},

		getProvinceCityCounty(rows) {
			// let province = this.helper.strNullReplace(rows.to_province, "");
			let city = this.check.strNullReplace(rows.to_city, "");
			let county = this.check.strNullReplace(rows.to_county, "");
			return city + '-' + county;
		},
		getOrderListData(type) {
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (level == 1 || level == 0) {
				this.carListData(type);
			} else{
				this.orderList = [];
				this.mescroll.endSuccess(this.orderList.length);  
				this.emptyType = 'order';
				this.emptyShow = true;
				// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
			}
		},

		carListData(type) {
			if (!this.check.isLogin()) { 
				return
			}
			var data = {
				journey_status: '20',
				page: this.pagenum,
				page_size:this.pagesize, 
			};
			let level = uni.getStorageSync(this.preutils.accountLevel);
			if (level == 1) {
				var userinfo= uni.getStorageSync(this.preutils.userinfo)
				data.destination_site_id = userinfo.site_id;
			}
			this.emptyShow = false;
			// if (this.$refs.loadingCover) this.$refs.loadingCover.show;
			this.http.sendRequest({
				api: this.api.order.journeyList,
				data: data,
				success: res => {
					this.emptyShow = true;
					this.emptyType = 'order';
					let newArr = [];
					let msg = res.message;
					if (res.code == '1' && res.data) {
						newArr = res.data.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					console.log(res)
					this.mescroll.endSuccess(newArr.length);
					//设置列表数据
					if (this.pagenum == 1) this.orderList = []; //如果是第一页需手动制空列表
					this.orderList = this.orderList.concat(newArr); //追加新数据
					// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					this.emptyType = 'order';
					this.emptyShow = true;
					// if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		 
		toWaybillList(item) {
			console.log(item)
			this.$util.redirectTo('/pages/order/order-list/allocation-order-list', {
				journey_id: this.check.strNullReplace(item.journey_id,''), 
			});
		}, 
  
	}
};